# -*- coding: utf-8 -*-
# @Time : 2021/7/27 上午9:39
# @Author : fugang_le

from src.main import identification_process, classify_identify_process
from src.classification.predict import Classification
from src.utils.log_util import logger

classifier = Classification()


# 需要先分类然后物料检索
class ClassifyAndIdentify:
    def __init__(self):
        pass

    def predict(self, price_type, grid_type,  material_name, material_sepc, price_conditions, threshold, topk=10):
        classifier_input = [{'material_name':material_name, 'material_sepc':material_sepc}]
        classification = classifier.predict(price_type, classifier_input, topk=1)
        classification = classification[0][0][0]
        logger.info("{} classification: {}".format(material_name, classification))
        result = classify_identify_process(price_type, grid_type, classification, material_name, material_sepc, price_conditions, threshold, topk=topk)
        logger.info("result (print only 1): {}".format(result[:1]))
        return result


# 不需要分类，类别进行传参
class Identification:
    def __init__(self):
        pass

    def predict(self, price_type, grid_type, classification, materialName, sepc, price_conditions, threshold, topk=100):
        result = identification_process(price_type, grid_type, classification, materialName, sepc, price_conditions, threshold, topk=topk)
        logger.info("result (print only 1): {}".format(result[:1]))
        return result